<?php

class Acl  
{

	public function isAllowed()
	{ 
		
		$aNamespace = new Zend_Session_Namespace('Zend_Auth');
	    
  		$data_url = explode("/",$_SERVER['REQUEST_URI']) ; 
		
  		//var_dump($data_url) ; 
  		
  		// get enviroment data ( module , controller , action  ... ) 
		$application = $data_url[1] ; 

		
		// verify controller
		if(!isset($data_url[2]))
		$controller = "index" ; 
		else
		$controller = $data_url[2] ;
		// verify action 
		if(!isset($data_url[3]) || $data_url[3] == "" )
		$action  = "index" ; 
		else
		$action = $data_url[3] ;
		

		
		//echo $controller." - ".$action  ; 
		
		
		// verify if authenticated
		if(isset($aNamespace->acl))
		{ 
			//print_r($aNamespace->acl) ;
			
			for($i = 0  ; sizeof($aNamespace->acl) > $i ; $i ++)
			{ 
				//echo $aNamespace->acl[$i]["module"];  
				
				if($aNamespace->acl[$i]["module"] == $module && $aNamespace->acl[$i]["controller"]== $controller && $aNamespace->acl[$i]["action"]== $action  )
				{  
					// if admin always allow all 
					if($aNamespace->acl[$i]["admin"] != $admin )
					{ 

						if($aNamespace->acl[$i]["user"] != $user )  
						{ 
							return "deny" ;
						}
					} 
				} 
			}
			
			
			
		}
		else
		{ 
			return "deny" ;
		}
		
		
		
		
		
		
	}
	
	
	
	
	
}


?>